import 'package:earn_money/pages/signup_page.dart';
import 'package:earn_money/pages/view_page.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

class RegisterPage extends StatefulWidget {
  const RegisterPage({super.key});

  @override
  State<RegisterPage> createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> {

  var ischecked = false;

  @override
  Widget build(BuildContext context) {
    
    var title =  Container(
      color: Colors.transparent, // Set the color to transparent
      padding: const EdgeInsets.fromLTRB(16, 100, 16, 16), // Add top padding of 100
      child: const Text(
        'RichRush',
        textAlign: TextAlign.center,
        style: TextStyle(
          color: Colors.black, // Set the text color to black
          fontSize: 32,
          fontWeight: FontWeight.bold,
        ),
      ),
    );

     var title2 =  Container(
      color: Colors.transparent, // Set the color to transparent
      padding: const EdgeInsets.all(8), // Add top padding of 100
      child: const Text(
        'Sign Up',
        textAlign: TextAlign.center,
        style: TextStyle(
          color: Colors.grey, // Set the text color to black
          fontSize: 25,
          fontWeight: FontWeight.bold,
        ),
      ),
    ); 

     var googleSignUpButton = Container(
      padding:  const EdgeInsets.fromLTRB(20,10,20,10),
      child: ElevatedButton.icon(
        onPressed: () {
          // Add your Google sign-in logic here
        },
        icon: const Icon(Icons.login),
        label: const Text('Sign up with Google Account'),
      ),
    );

    var emailSignUpButton = Container(
      padding:  const EdgeInsets.fromLTRB(20,10,20,10),
      child: ElevatedButton.icon(
        onPressed: () {
          // Add your Google sign-in logic here
            Navigator.push(
                      context, 
                      MaterialPageRoute(builder: (context) => const SignupPage())
             );
        },
        icon: const Icon(Icons.email),
        label: const Text('Sign up with Email'),
      ),
    );
    
    var termsAndPrivacy = Container(
      padding: const EdgeInsets.all(8),
      child: Row(
        children: [
          Checkbox(
            value: ischecked, // Set the initial value of the checkbox
            onChanged: (bool? value) {
              // Add your logic to handle checkbox changes here
              setState(() {
                ischecked = !ischecked;
              });
            },
          ),
          Expanded(child: 
              RichText(
                text: TextSpan(
                  style: const TextStyle(
                        color: Colors.black,
                        fontSize: 16,
                  ),
                  children: <TextSpan>[
                    const TextSpan(
                      text: 'By signing up, you agree to our '),
                    TextSpan(
                      text: 'terms of service',
                      style: const TextStyle(
                        color: Colors.green,
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                      ),
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          // Add your logic to handle the terms of service link here
                          Navigator.push(context, 
                              MaterialPageRoute( 
                                builder: (context) => const ViewPage(title: 'Terms of Service', url: 'http://192.168.1.185/service.html')
                              ));
                        },
                    ),
                    const TextSpan(text: ' and '),
                    TextSpan(
                      text: 'Privacy Policy',
                      style: const TextStyle(
                        color: Colors.green,
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                      ),
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          // Add your logic to handle the privacy policy link here
                            Navigator.push(context, 
                              MaterialPageRoute( 
                                builder: (context) => const ViewPage(title: 'Privacy Policy', url: 'http://192.168.1.185/service.html')
                              ));
                        },
                    ),
                  ],
                ),
              )
          )

      ],)
    );
  

  var loginText = Container(
    padding: const EdgeInsets.fromLTRB(20, 100, 20, 20),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        const Text(
          "Already have an account?",
          style: TextStyle(
            color: Colors.black,
            fontSize: 16,
          ),
        ),
        Container(
          margin: const EdgeInsets.only(left: 10),
          child: 
          GestureDetector(
            onTap: () {
              // Add your navigation logic here
              setState(() {
                  Navigator.pop(context);
              });
            },
            child: const Text(
              "Login",
              style: TextStyle(
                color: Colors.green,
                fontSize: 16,
                fontWeight: FontWeight.bold,
              ),
            ),
          ), 
        ),
      ],
    ),
  );

    return Scaffold(
      body: Column(
        children: [
          Expanded(
            child: ListView(
              children: [
                title,
                title2,
                googleSignUpButton,
                emailSignUpButton,
                termsAndPrivacy,
                loginText,
              ],
            ),
          ),
        ],
      ),
    );
  }
}